<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button id="btn">发送</button>
  <script>
    // 创建WebSocket对象, 连接ws服务器
    const socket = new WebSocket('ws://localhost:8082')
    socket.onopen = () => {
      console.log('连接服务器成功了')
    }

    // 绑定接收消息的监听
    socket.addEventListener('message', (event) => {
      const {status} = JSON.parse(event.data)
      if (status==='已支付') {
        alert('跳转去支付成功的页面')
      }
    })

    document.getElementById('btn').onclick = () => {
      // 向服务器发消息
      socket.send('abc')
    }

  </script>
</body>
</html>